/**
 * 封装axios的模块
 */
import axios from "axios";
import Cookies from 'js-cookie'

//cookie 类相关方法
 const  getToken = function (key) {
  return Cookies.get(key);
}



const instance = axios.create({
    baseURL:window.serviceUrl,
    timeout: 100000,
    xsrfHeaderName: "X-CSRF-TOKEN",
    withCredentials: false,
});


/**
 * 添加请求拦截器, 处理请求参数问题以及token问题
 */
instance.interceptors.request.use(
    (config) => {
        // 是否需要设置 token
        const isToken = (config.headers || {}).isToken === false;
        if (getToken("access_token") && !isToken) {
            config.headers["Authorization"] = "Bearer " + getToken("access_token"); // 让每个请求携带自定义token 请根据实际情况自行修改
        }
        return config;
    },
    (error) => {
        Promise.reject(error);
    }
);



export default instance;
